/**
 * 修改密码窗口
 */
DC.front.win.CheckoutProjectWin = function(params, config) {
	var ckpWin = this;
	
	var checkoutProject_formPanel = new DC.front.CheckoutProjectFormPanel();
	
	DC.front.win.CheckoutProjectWin.superclass.constructor.call(this, Ext.apply({
    	id : 'checkout_project_win',
    	title : 'Checkout Project',
    	width : 430,
    	height : 220,
        border : true,
        bodyBorder : true,
        layout : 'fit',
        modal : true,
        closeAction : 'close',
        items :[ checkoutProject_formPanel ],
        buttons : [{
        	id : 'checkout_project_win_checkout_btn',
			text : 'Checkout',
			disabled : true,
			handler :function(){
				checkoutProject_formPanel.checkout();
			} 
		}, {
			text : 'Cancle',
			handler :function(){
				ckpWin.close();
			} 
		}]
    }, config ||{}));
};

Ext.extend(DC.front.win.CheckoutProjectWin, Ext.Window, {
	
});

DC.front.CheckoutProjectFormPanel = function(params, config) {
	var ckpfp = this;
	DC.front.CheckoutProjectFormPanel.superclass.constructor.call(this, Ext.apply({
           id : 'checkoutProject_formPanel',
           header : false,
           labelWidth : 90,
           labelAlign : 'right',
           buttonAlign : 'center',
           frame : true,
           defaultType : 'textfield',
           defaults : {
               width : 300,
               labelStyle : 'margin:5px auto'
           },
           items: [{
        	   id : 'checkoutProject_formPanel_projectName_field',
           	   name : 'projectName',
               fieldLabel: '<font color="red">*</font>Project Name',
               style:'margin:5px auto',
               allowBlank: false, // 表单控件不可以为空
               blankText:"Project name can't be empty.",
               regex: /^[^\/\\<>\*\?\:"\|\.]*[^\/\\<>\*\?\:"\|\.]$/,
               regexText: 'The project name cannot contain "/\<>*?:"|."',
               enableKeyEvents: true, // 只有将此属性设置成true，此控件的键盘事件才生效
               listeners : {
	        		keyup : function() {
	        			var created_btn = Ext.getCmp('checkout_project_win_checkout_btn');
	        			if (ckpfp.formFieldIsNotEmpty()) {
	        				created_btn.enable();
	        			} else {
	        				created_btn.disable();
	        			}
	        		}
	           }
           }, {
        	   id : 'checkoutProject_formPanel_userName_field',
           	   name : 'userName',
               fieldLabel: '<font color="red">*</font>User Name',
               style:'margin:5px auto',
               allowBlank: false, // 表单控件不可以为空
               blankText:"User name can't be empty.",
               enableKeyEvents: true, // 只有将此属性设置成true，此控件的键盘事件才生效
               listeners : {
	        		keyup : function() {
	        			var created_btn = Ext.getCmp('checkout_project_win_checkout_btn');
	        			if (ckpfp.formFieldIsNotEmpty()) {
	        				created_btn.enable();
	        			} else {
	        				created_btn.disable();
	        			}
	        		}
	           }
           }, {
        	   id : 'checkoutProject_formPanel_password_field',
           	   inputType: 'password',
               name: 'password',
               fieldLabel: '<font color="red">*</font>Password',
               style:'margin:5px auto',
               allowBlank: false, // 表单控件不可以为空
               blankText:"Password can't be empty.",
               enableKeyEvents: true, // 只有将此属性设置成true，此控件的键盘事件才生效
               listeners : {
	        		keyup : function() {
	        			var created_btn = Ext.getCmp('checkout_project_win_checkout_btn');
	        			if (ckpfp.formFieldIsNotEmpty()) {
	        				created_btn.enable();
	        			} else {
	        				created_btn.disable();
	        			}
	        		}
	           }
           }, {
        	   id : 'checkoutProject_formPanel_url_field',
           	   name: 'url',
               fieldLabel: '<font color="red">*</font>Url',
               style:'margin:5px auto',
               allowBlank: false, // 表单控件不可以为空
               blankText:"Url can't be empty.",
               regex : /^https?:\/\/.*$/,
               regexText : 'The site must be "http://" beginning.',
               enableKeyEvents: true, // 只有将此属性设置成true，此控件的键盘事件才生效
               listeners : {
	        		keyup : function() {
	        			var created_btn = Ext.getCmp('checkout_project_win_checkout_btn');
	        			if (ckpfp.formFieldIsNotEmpty()) {
	        				created_btn.enable();
	        			} else {
	        				created_btn.disable();
	        			}
	        		}
	           }
           }]
   }, config ||{}));
};

Ext.extend(DC.front.CheckoutProjectFormPanel, Ext.form.FormPanel, {
	
	 // 添加用户的响应事件
	checkout : function() {
		
		var html = '<div class="progress" id="checkout_project_win_progress">' + 
		               '<span for=".">Checkouting, please wait</span>' +
		    	       '<img src="././image/ico_progerssbar_editnplace.gif" alt="checkout"></img>' +
		           '</div>';
		DC.obj.msg_tabPanel.setActiveTab(1);
		DC.obj.msg_tabPanel.progressPanel.update(html);
		if (this.getForm().isValid()) {
			var projectNameVal = Ext.getCmp('checkoutProject_formPanel_projectName_field').getValue();
			var userNameVal = Ext.getCmp('checkoutProject_formPanel_userName_field').getValue();
			var passwordVal = Ext.getCmp('checkoutProject_formPanel_password_field').getValue();
			var urlVal = Ext.getCmp('checkoutProject_formPanel_url_field').getValue();
			Ext.getCmp("checkout_project_win").close();
			Ext.Ajax.request({
			    url : DC.url.CHECKOUT_PROJECT,
			    method : 'POST',
			    params : {
			    	projectName : projectNameVal,
			    	userName : userNameVal,
			    	password : passwordVal,
			    	url : urlVal
			    },
			    success : function(response, options){
			    	var res = Ext.util.JSON.decode(response.responseText);
                	if (res.success) {
                		Ext.example.msg('Prompt', res.msg, 'prompt');
                	} else {
                		Ext.example.msg('Prompt', res.msg, res.type);
                	}
			    },
			    failure : function(response, options){
                	Ext.example.msg('Verification Win', response.responseText, 'error');
			    }
		    });
			/*this.getForm().submit({
		           clientValidation: true,
		           method: 'post',
		           url: DC.url.CHECKOUT_PROJECT,
		           success: function(form, action){
	                	var res = action.result;
	                	if (res.success) {
	                		Ext.example.msg('Prompt', res.msg, 'prompt');
	                	} else {
	                		Ext.example.msg('Prompt', res.msg, res.type);
	                	}
		           },
		           failure: function(form, action){
		               switch (action.failureType) {
			                case Ext.form.Action.CLIENT_INVALID: // 当客户端验证失败时执行
			                     break;
			                case Ext.form.Action.CONNECT_FAILURE:
			                	 Ext.example.msg('Prompt Win', 'Network connection failure, so fail to commit.', 'error');
			                     break;
			                case Ext.form.Action.SERVER_INVALID: // 当服务器端的success属性的值返回false时执行
			                	 Ext.example.msg('Prompt Win', action.result.message, 'error');
			            }
		           }
		     });*/
		}
   },
   
   formFieldIsNotEmpty : function() {
	   var projectName = Ext.getCmp('checkoutProject_formPanel_projectName_field').getValue().trim();
	   var userName = Ext.getCmp('checkoutProject_formPanel_userName_field').getValue().trim();
	   var password = Ext.getCmp('checkoutProject_formPanel_password_field').getValue().trim();
	   var url = Ext.getCmp('checkoutProject_formPanel_url_field').getValue().trim();
	   if (projectName != '' && userName != '' && password != '' && url != '') {
		   return true;
	   }
	   return false;
   }
});